package top.lcm889.oj.leetcodeTop200;

/**
 * @author Coder-lcm
 * @date 2021/5/3
 */
public class LC7_整数反转 {

    public int reverse(int x) {
        if (x == 0) return 0;
        boolean fushu = x < 0;
        if (fushu) {
            x = Math.abs(x);
        }
        StringBuilder sb = new StringBuilder(String.valueOf(x));
        sb.reverse();
        int res = 0;
        try{
            res = Integer.parseInt(sb.toString());
        }catch (Exception e) {
            return 0;
        }
        return fushu ? - res : res;
    }

    public static void main(String[] args) {
        LC7_整数反转 test = new LC7_整数反转();
        System.out.println(test.reverse(1534236469));

    }

}
